package arrays;

public class Person implements Comparable{

	String name;
	int age;
	
	public Person(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return "Person [name=" + name + ", age=" + age + "]";
	}

	@Override
	public int compareTo(Object o) {
		
		Person op = (Person)o;
		
		int nameCompareResult = name.compareTo(op.name);
		if(nameCompareResult != 0){
			
			return nameCompareResult;
		}else{
			
			if(age > op.age){
				
				return 1;
			}else if(age == op.age){
				
				return 0;
			}else{
				
				return -1;
			}
		}
	}
}
